<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Update Event</title>
    </h:head>
    <h:body>
        <ui:composition template="./templateuser.xhtml">
            <ui:define name="center">
                <h:form id="formid">
                    <p:panel header="Create Event">
                        <h:panelGrid columns="3" id="eventGrid">
                            <h:outputLabel for="name">Name:</h:outputLabel>
                            <p:inputText id="name" value="#{updateEventBean.event.name}">
                                <p:ajax update="namemsg"/>
                            </p:inputText>
                            <p:message id="namemsg" for="name" />

                            <h:outputLabel for="description">Description:</h:outputLabel>
                            <p:inputText id="description" value="#{updateEventBean.event.description}">
                                <p:ajax update="descriptionmsg"/>
                            </p:inputText>
                            <p:message id="descriptionmsg" for="description" />
                            
                            <p:outputLabel for="date" value="Date:" />
                            <p:calendar id="date" value="#{updateEventBean.event.date}"  validator="#{updateEventBean.validateDate}">
                                <p:ajax update="datemsg"/>
                            </p:calendar>
                            <p:message id="datemsg" for="date" />
                            
                            <p:outputLabel for="startime" value="Start time:" />
                            <p:calendar id="startime" value="#{updateEventBean.event.startTime}" pattern="HH:mm a" timeOnly="true" >
                                <p:ajax update="startimemsg"/>
                            </p:calendar>
                            <p:message id="startimemsg" for="startime" />
                            
                            <p:outputLabel for="endtime" value="End time:" />
                            <p:calendar id="endtime" value="#{updateEventBean.event.endTime}" pattern="HH:mm a" timeOnly="true"  validator="#{updateEventBean.validateEndTime}">
                                <p:ajax update="endtimemsg"/>
                            </p:calendar>
                            <p:message id="endtimemsg" for="endtime" />
                            
                            <h:outputLabel for="address">Address:</h:outputLabel>
                            <p:inputText id="address" value="#{updateEventBean.event.place.address}">
                                <p:ajax update="addressmsg"/>
                            </p:inputText>
                            <p:message id="addressmsg" for="address" />
                            
                            <p:outputLabel for="country" value="Country: " />
                            <p:selectOneMenu id="country" value="#{updateEventBean.country}" style="width:150px">
                                <p:ajax listener="#{updateEventBean.onCountryChange}" update="city" />
                                <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
                                <f:selectItems value="#{updateEventBean.countries}" />
                            </p:selectOneMenu>
                            <p:message id="countrymsg" for="country" />

                            <p:outputLabel for="city" value="City: " />
                            <p:selectOneMenu id="city" value="#{updateEventBean.city}" style="width:150px">
                                <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
                                <f:selectItems value="#{updateEventBean.cities}" />
                            </p:selectOneMenu>
                            <p:message id="citymsg" for="city" />
                            
                            <h:outputLabel for="eventvisibility">Public event:</h:outputLabel>
                            <p:selectBooleanCheckbox id ="eventvisibility" value="#{updateEventBean.event.visibility}">
                            </p:selectBooleanCheckbox>
                            <p:message id="eventvisibilitymsg" for="eventvisibility" />
                            
                        </h:panelGrid>
                        
                        <p:toolbar style="margin-top: 20px">
                            <p:toolbarGroup align="right">
                                <p:commandButton value="Save" update="eventGrid"
                                         action="#{updateEventBean.save()}" />
                            </p:toolbarGroup>
                        </p:toolbar>
                        
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
